package github.sf.fw.check;

import github.sf.fw.check.exception.ParameterValidationException;

import java.util.Collection;
import java.util.function.Supplier;

public class ArgsCheck {
    public static void emptyCheck(Object value, String hint) {
        if (value == null) {
            throw new ParameterValidationException(hint);
        }
        if (value instanceof CharSequence) {
            if (((CharSequence) value).length() == 0) {
                throw new ParameterValidationException(hint);
            }
        }
        if (value instanceof Collection) {
            if (((Collection<?>) value).isEmpty()) {
                throw new ParameterValidationException(hint);
            }
        }
    }

    public static void predicate(Supplier<Boolean> expr, String hint) {
        if (expr.get()) {
            throw new ParameterValidationException(hint);
        }
    }
}
